$(function() {
	var grid = $('#grid')._datagrid({
		checkOnSelect : false,
		selectOnCheck : false,
		fitColumns : true,
		showFooter:true,
		url : "order/list.html", 
		onBeforeLoad : function(param) {
			if (!$('#queryForm').form('validate')) {
				return false;
			}
			var queryParams = $('#queryForm')._formToJson();
			for (i in queryParams) {
				param[i] = queryParams[i];
			}
		}
	});
    $('#queryButton').click(function(){
        var params = $('#queryForm')._formToJson();
        $(grid).datagrid('load',params);
    });
});
var formatter = {
	transfer_amount : function(value, rowData, rowIndex) {
    	return (rowData.amount-rowData.brokerage).toFixed(2);
	},
/*	dealsms : function(value, rowData, rowIndex) {
		if(rowData.deal!=null){
			return rowData.deal+"/"+rowData.alls;
		}else{
			return "";
		}
	},
	transms : function(value, rowData, rowIndex) {
		if(rowData.deal!=null){
			return rowData.transfer+"/"+rowData.alls;
		}else{
			return "";
		}
	},*/
	cbState : function(value, rowData, rowIndex){
      switch(value) {
      case 0:
      	if(rowData.refundStatus==4){
      		return "<font color='#CD950C'>转账关闭</font>";
      	}else{
      		return "<font color='#CD950C'>处理成功</font>";
      	}
      case 1:
        return "<font color='#EE0000'>待处理</font>";
      case 2:
        return "<font color='#EE0000'>被拒绝</font>";
      case 3:
        return "<font color='#CD00CD'>处理中</font>";
      case 4:
      return "<font color='#CD950C'>处理成功</font>";
      case 5:
        return "<font color='#EE0000'>处理失败</font>";
      }
        return "";
    },
    refundStatus : function(value, rowData, rowIndex){
      switch(value) {
      case 0:
        return "<font color='#000000'>未申请</font>";
      case 1:
        return "<font color='#CD00CD'>退款中</font>";
      case 2:
        return "<font color='#CD00CD'>退款通过</font>";
      case 3:
      return "<font color='#EE0000'>退款拒绝</font>";
      case 4:
        return "<font color='#CD950C'>退款完成</font>";
      }
        return "";
    },
    opt : function(value, rowData, rowIndex){
    	var html="";
    	if(rowData.cbState==4){//转账成功后才有转账明细
    		html+='<a class="spacing a-blue" onclick="detail('+rowIndex+');" href="javascript:void(0);">转账明细</a>';  
    	};
    	if(rowData.state==1){ //短信日志  支付成功
    		html+='<a class="spacing a-blue" onclick="smsdetail('+rowIndex+');" href="javascript:void(0);">短信日志</a>';
    	}
    	return html;
    }
};
//转账明细
function detail(rowIndex) {
	var data = $('#grid').datagrid('getRows')[rowIndex];
	var downurl='/orderOownloadPdf.html?billId='+data.billId;
	document.location.href = downurl;
}

//短信日志
function smsdetail(rowIndex) {
    var data = $('#grid').datagrid('getRows')[rowIndex];
    document.location.href = "/menus/pushsms.html?orderNo=" + data.order_num;
}
